home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- ** **
- ** Module: NetSprocket.h **
- ** **
- ** **
- ** Purpose: Apple Game Sprockets Include file **
- ** **
- ** **
- ** **
- ** Copyright (C) 1996 Apple Computer, Inc. All rights reserved. **
- ** **
- ** **
- *****************************************************************************/
-
- #ifndef __NETSPROCKET_H__
- #define __NETSPROCKET_H__
-
- #ifndef SystemSevenOrLater
- #define SystemSevenOrLater 1
- #endif
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=power
- #endif
-
- #pragma enumsalwaysint on
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #ifndef __OPENTRANSPORT__
- #include <OpenTransport.h>
- #endif
-
- #ifndef __OPENTPTINTERNET__
- #include <OpenTptInternet.h>
- #endif
-
- #define kNSMaxPlayerNameLen 31
- #define kNSMaxGroupNameLen 31
- #define kNSMaxPasswordLen 31
- #define kNSMaxGameNameLen 31
-
-
- typedef void *TNetGameObject;
- typedef SInt32 TGameID;
- typedef SInt32 TPlayerID;
- typedef TPlayerID TGroupID;
- typedef UInt32 TPlayerType;
- typedef SInt32 TNetFlags;
- typedef void *TGameAddressRef;
- typedef UInt32 TSerialPort;
-
- /* Topology types */
- typedef enum
- {
- kNSClientServer = 0x00000001
- } TTopology;
-
-
- /* Individual player info */
- typedef struct TPlayerInfo
- {
- TPlayerID id;
- TPlayerType type;
- Str31 name;
- UInt32 groupCount;
- TGroupID groups[kVariableLengthArray];
- } TPlayerInfo, *TPlayerInfoPtr;
-
-
- /* list of all players */
- typedef struct TPlayers
- {
- UInt32 count;
- TPlayerInfoPtr playerInfo[kVariableLengthArray];
- } TPlayers, *TPlayersPtr;
-
-
- /* Individual group info */
- typedef struct TGroupInfo
- {
- TGroupID id;
- UInt32 playerCount;
- TPlayerID players[kVariableLengthArray];
- } TGroupInfo, *TGroupInfoPtr;
-
-
- /* List of all groups */
- typedef struct TGroups
- {
- UInt32 count;
- TGroupInfoPtr players[kVariableLengthArray];
- } TGroups, *TGroupsPtr;
-
-
- /* Game information */
- typedef struct TGameInfo
- {
- UInt32 maxPlayers;
- UInt32 currentPlayers;
- UInt32 currentGroups;
- TTopology topology;
- UInt32 reserved;
- Str31 name;
- Str31 password;
- } TGameInfo;
-
-
- /* Structure used for sending and receiving network messages */
- typedef struct TNetMessageHeader
- {
- UInt32 version; /* Used by NetSprocket. Don't touch this */
- SInt32 what; /* The kind of message (e.g. player joined) */
- TPlayerID from; /* ID of the sender */
- TPlayerID to; /* (player or group) id of the intended recipient */
- UInt32 id; /* Unique ID for this message & (from) player */
- UInt32 when; /* Timestamp for the message */
- UInt32 messageLen; /* Bytes of data in the entire message (including the header) */
- } TNetMessageHeader;
-
-
- typedef struct TNSErrorMessage
- {
- TNetMessageHeader header;
- OSStatus error;
- } TNSErrorMessage;
-
-
- typedef struct TJoinRequestMessage
- {
- TNetMessageHeader header;
- Str31 name;
- Str31 password;
- UInt32 type;
- UInt32 customDataLen;
- UInt8 customData[kVariableLengthArray];
- } TJoinRequestMessage;
-
-
- typedef struct TJoinApprovedMessage
- {
- TNetMessageHeader header;
- } TJoinApprovedMessage;
-
-
- typedef struct TJoinDeniedMessage
- {
- TNetMessageHeader header;
- Str255 reason;
- } TJoinDeniedMessage;
-
-
- typedef struct TPlayerJoinedMessage
- {
- TNetMessageHeader header;
- UInt32 playerCount;
- TPlayerInfo playerInfo;
- } TPlayerJoinedMessage;
-
-
- typedef struct TPlayerLeftMessage
- {
- TNetMessageHeader header;
- UInt32 playerCount;
- TPlayerID playerID;
- } TPlayerLeftMessage;
-
-
-
- /* Different kinds of messages */
- enum
- {
- kJunk = 0x10000000, /* will be sent (try once) when there is nothing else pending */
- kNormal = 0x20000000, /* will be sent immediately (try once) */
- kRegistered = 0x30000000 /* will be sent immediately (guaranteed, in order) */
- };
-
-
- /* Options for message delivery */
- enum
- {
- kNSFailIfPipeFull = 0x00000001,
- kSelfSend = 0x00000002,
- kBlocking = 0x00000004
- };
-
-
- /* Options for Hosting Joining, and Deleting games */
- enum
- {
- kNSNeedReliableTransport = 0x00000001,
- kNSForceTerminateGame = 0x00000002
- };
-
- /* T NetMessage "what" types */
- /* Apple reserves all negative "what" values (anything with bit 32 set) */
- enum
- {
- kSystemMessage = 0x80000000,
- kErrorMessage = kSystemMessage | 0x7FFFFFFF,
- kNSJoinRequest = kSystemMessage | 0x00000001,
- kNSJoinApproved = kSystemMessage | 0x00000002,
- kNSJoinDenied = kSystemMessage | 0x00000003,
- kNSPlayerJoined = kSystemMessage | 0x00000004,
- kNSPlayerLeft = kSystemMessage | 0x00000005,
- kNSHostChanged = kSystemMessage | 0x00000006
- };
-
-
- /* Special TPlayerIDs for sending messages */
- enum
- {
- kNSAllPlayers = 0x00000000,
- kNSServerOnly = 0xFFFFFFFF
- };
-
-
- /* Transport protocols returned by DoModalHostDialog */
- enum
- {
- kAppleTalk = 0x00000001,
- kTCPIP = 0x00000002,
- kSerial = 0x00000004
- };
-
-
- /* Error codes (range: -4500 through -4001) */
- enum
- {
- kNSNoError = 0,
- initializationFailedErr = -4500,
- alreadyInitializedErr,
- topologyNotSupportedErr,
- messageSizeTooBigErr,
- bufferTooSmallErr,
- receiveDataErr,
- protocolNotAvailableErr,
- invalidObjectErr,
- invalidNetMessageErr,
- invalidParameterErr,
- OTNotPresentErr,
- hostFailedErr,
- notHostAddressErr,
- memAllocationErr,
- invalidProtocolErr,
- alreadyAdvertisingErr,
- noTypeSpecifiedErr,
- notAdvertisingErr,
- bogusDataErr,
- tooMuchDataErr,
- bogusAddressErr,
- freeQExhaustedErr,
- noSuchUserErr,
- nameTakenErr,
- portTakenErr,
- gameInProgressErr,
- featureNotImplementedErr,
- nameRequiredErr,
- invalidPlayerIDErr,
- invalidGroupIDErr,
- noPlayersErr,
- noGroupsErr,
- noHostVolunteersErr
- };
-
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- /************************ Initialization ************************/
-
- OSStatus InitializeNetSprocket(UInt32 inStandardMessageSize, UInt32 inBufferSize, UInt32 inQElements);
-
-
- /*********************** Human Interface ************************/
-
- TGameAddressRef DoModalJoinDialog(ConstStr31Param inGameType, ConstStr255Param inEntityListLabel, Str31 ioName, Str31 ioPassword);
-
- UInt32 DoModalHostDialog(ConstStr255Param inHeading, InetPort *ioPort, Str31 ioGameName, Str31 ioPlayerName, Str31 ioPassword);
-
-
- /********************* Hosting and Joining **********************/
-
- OSStatus NewGame(TNetGameObject *outGame, UInt32 inMaxPlayers, ConstStr31Param inGameName, ConstStr31Param inPassword, ConstStr31Param inPlayerName, TPlayerType inPlayerType, TTopology inTopology, TNetFlags inFlags);
-
- OSStatus HostGameOnAppleTalk(TNetGameObject inGame, ConstStr31Param inGameType, UInt32 inMaxRTT);
-
- OSStatus HostGameOnTCPIP(TNetGameObject inGame, InetPort *ioPort, UInt32 inMaxRTT);
-
- OSStatus HostGameOnSerial(TNetGameObject inGame, UInt32 inPort, UInt32 inMinBaud);
-
- OSStatus StopHostingAppleTalk(TNetGameObject inGame);
-
- OSStatus StopHostingTCPIP(TNetGameObject inGame);
-
- OSStatus StopHostingSerial(TNetGameObject inGame, UInt32 inPort);
-
- OSStatus JoinGame(TNetGameObject *outGame, TGameAddressRef inAddress, ConstStr31Param inName, ConstStr31Param inPassword, TPlayerType inType, UInt32 inUserDataLen, void *inUserData, TNetFlags inFlags);
-
- OSStatus DeleteGame(TNetGameObject inGame, TNetFlags inFlags);
-
-
- typedef Boolean (*TJoinRequestHandlerProcPtr)(TNetGameObject inGame, TJoinRequestMessage *inMessage, void* inContext);
-
- OSStatus InstallJoinRequestHandler(TNetGameObject inGame, TJoinRequestHandlerProcPtr inHandler, void *inContext);
-
-
- /************************** Messaging **************************/
-
- OSStatus SendNetMessage(TNetGameObject inGame, TNetMessageHeader *inMessage, TNetFlags inFlags);
-
- TNetMessageHeader *GetNextNetMessage(TNetGameObject inGame);
-
- void ReleaseNetMessage(TNetGameObject inGame, TNetMessageHeader *inMessage);
-
- /* Async messaging support */
- typedef void (*TMessageHandlerProcPtr)(TNetGameObject inGame, TNetMessageHeader *inMessage, void* inContext);
-
- OSStatus InstallNetMessageHandler(TNetGameObject inGame, TMessageHandlerProcPtr inHandler, void *inContext);
-
-
- /********************* Player Information **********************/
-
- TPlayerID GetMyPlayerID(TNetGameObject inGame);
-
- OSStatus GetPlayerInfo(TNetGameObject inGame, TPlayerID inPlayerID, TPlayerInfoPtr *outInfo);
-
- void ReleasePlayerInfo(TNetGameObject inGame, TPlayerInfoPtr inInfo);
-
- OSStatus GetPlayers(TNetGameObject inGame, TPlayersPtr *outPlayers);
-
- void ReleasePlayers(TNetGameObject inGame, TPlayersPtr inPlayers);
-
-
- /********************* Group Management **********************/
-
- OSStatus CreateGroup(TNetGameObject inGame, TGroupID *outGroupID);
-
- OSStatus DeleteGroup(TNetGameObject inGame, TGroupID inGroupID);
-
- OSStatus AddPlayerToGroup(TNetGameObject inGame, TGroupID inGroupID, TPlayerID inPlayerID);
-
- OSStatus RemovePlayerFromGroup(TNetGameObject inGame, TGroupID inGroupID, TPlayerID inPlayerID);
-
- OSStatus GetGroupInfo(TNetGameObject inGame, TGroupID inGroupID, TGroupInfoPtr *outInfo);
-
- void ReleaseGroupInfo(TNetGameObject inGame, TGroupInfoPtr inInfo);
-
- OSStatus GetGroups(TNetGameObject inGame, TGroupsPtr *outGroups);
-
- void ReleaseGroups(TNetGameObject inGame, TGroupsPtr inGroups);
-
-
- /************************** Utilities ***************************/
-
- void ClearNetMessageHeader(TNetMessageHeader *inMessage);
-
- UInt32 GetCurrentTimeStamp(TNetGameObject inGame);
-
- UInt32 GetRoundTripTime(TNetGameObject inGame, TPlayerID inPlayer, UInt32 inTimeout);
-
- TGameAddressRef OTAddressToGameAddressRef(OTAddress *inAddress);
-
- OTAddress *GameAddressRefToOTAddress(TGameAddressRef inAddress);
-
- void ReleaseGameAddressRef(TGameAddressRef inAddress);
-
-
-
- #ifdef __cplusplus
- }
- #endif
-
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=reset
- #endif
-
- #pragma enumsalwaysint reset
-
- #endif